#!/bin/sh

addr=$1
malware_name=$2
mode=$3
# Corresponding option of each mode: either cpu usage for calculation mode, or portno for port_listening mode.
crspd_option=$4
abs_path=$5

inst_dir="instantiation"

# Copy the source code to the /usr/bin/ of base image.
scp ${abs_path}${inst_dir}/malware_creation/dummy_malware root@${addr}:/usr/bin/${malware_name}

# Add code to rc.d/rc.local file.
if [ ${mode} = "calculation" ]; then
    scp ${abs_path}${inst_dir}/malware_creation/cpulimit/src/cpulimit root@${addr}:/usr/bin/
    command="\"exec -a cpusage cpulimit -l ${crspd_option} ${malware_name} ${mode} 1000 &\"";
    ssh root@${addr} "echo 'bash -c ${command}'  >> /etc/rc.d/rc.local";
else
    command="${malware_name} ${mode} ${crspd_option} &";
    ssh root@${addr} "echo '${command}'  >> /etc/rc.d/rc.local";
fi
